-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileMove_SFTP_generic.py
More file actions
40 lines (32 loc) · 1.15 KB
/
FileMove_SFTP_generic.py
File metadata and controls
40 lines (32 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import shutil
import paramiko
import shutil
#Takes user input for the full source path
source = input('Enter the full source directory:\n')
#Takes user input for the full destination path
destination = '/home/gcotto/Downloads/temp/'
filename = input(f'Enter the file name:\nFile will be moved to directory of {destination}\n')
full_destination = destination + filename
new_path = shutil.move(source,full_destination)
print(f'File has been moved to {full_destination}\n')
#Enter host IP below
host = ''
#Enter host port number below
port = 22
#Enter host username below
username = ''
#Enter host password below
password = ''
#Paramiko library connects via ssh to host parameters
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host,port,username,password)
sftp = ssh.open_sftp()
localpath = full_destination
print(f'Pulling file from {full_destination}\n')
sftp_path = '/media/ntfs/'+ filename
print(f'File will be moved to directory of {sftp_path}\nPlease wait as the upload process completes...\n')
sftp.put(localpath,sftp_path)
print(f'File has been uploaded to {sftp_path}\nVerify the results')
sftp.close()
ssh.close()