Question: I wrote a script to transfer a file the script creates to a remote server. The file name includes a variable for the date so

I wrote a script to transfer a file the script creates to a remote server. The file name includes a variable for the date so that each file is unique, but I do not know how to add a variable when I do the file path on sftp_client.put(r'C:\Users\PVL1NPP\Desktop\name_of_file' ,'test1.sh'), name-of_file is the variable.

def writeFile():

save_path = (r'C:\Users\PVL1NPP\Desktop')

name_of_file = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")

completeName = os.path.join(save_path, name_of_file+".sh")

file = open(completeName,'w')

file.write('hello')

file.close()

def connection(host, username, password, port="22"):

ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect(host.get(), port, username.get(), password.get())

sftp_client=ssh.open_sftp()

sftp_client.put(r'C:\Users\PVL1NPP\Desktop ame_of_file' ,'test1.sh')

sftp_client.close()

ssh.close()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!