Move files from one directory to another with Paramiko
Use the sftp.rename
:
sftp.rename(remotePath+'/tmp/'+fileName, remotePath+fileName)
Note that some SFTP servers fail the request, if the source and target directories are on different file systems.
If you need to move set of files from one folder to another, see:
Archive all files from one SFTP folder to another in Python
Directory transfers with Paramiko
You'll need to do this just like you would locally with python (if you weren't using shutils).
Combine os.walk()
, with sftp.mkdir()
and sftp.put()
. You may also want to check each file and directory with os.path.islink()
depending on whether you want to resolve symlinks or not.
Copy file from remote dir to remote sub directory using paramiko
You can try in the below way
a=paramiko.SSHClient()
a.set_missing_host_key_policy(paramiko.AutoAddPolicy())
a.connect('ip',username='user',password='passw')
stdin, stdout, stderr = a.exec_command("cp /sourc/file /target/file")
Copy a file to server with a different filename using Python Paramiko over ssh/sftp
So upload the file straight to the new name:
sftp.put("c:\file_a.txt", "/home/the_user/file_b.txt")
Python moving file on SFTP server to another folder
Use Connection.rename
:
sftp.rename(remote_dir + file, remote_backup_dir + file)
Obligatory warnings:
- Do not set
cnopts.hostkeys = None
, unless you do not care about security. For the correct solution see Verify host key with pysftp. - Do not use pysftp. It's dead. Use Paramiko. See pysftp vs. Paramiko.
Related Topics
Should I Use 'Has_Key()' or 'In' on Python Dicts
Change the Color of Text Within a Pandas Dataframe HTML Table Python Using Styles and CSS
Connect Wifi with Python or Linux Terminal
If _Name_ == '_Main_'' Equivalent in Ruby
How to Write a Python Module/Package
Compiling Numpy with Openblas Integration
How to Make a Multi-Color Line in Matplotlib
What Does Preceding a String Literal with "R" Mean
How to Execute Raw SQL in Flask-Sqlalchemy App
Does Anybody Know How to Identify Shadow Dom Web Elements Using Selenium Webdriver
Python Linux Dmidecode, How to Obtain Hw Info by Parsing
Parallel Processing from a Command Queue on Linux (Bash, Python, Ruby... Whatever)
Matplotlib: Format Axis Offset-Values to Whole Numbers or Specific Number
Automatically Create Requirements.Txt
How to Access "Static" Class Variables Within Methods in Python