Currently I am doing below task.
- Create a small file in Windows using Python
- Transfer this file to remote Unix environment using Paramiko Python library SFTP module
Problem faced:
Newline created on Windows is not properly converted to Unix new line character during the transfer. I see ^M
characters inside the file on my remote host.
Any idea or suggestion how can I get rid of this behaviour.
When I do the transfer of the same file using WinSCP, I do not face this problem. I guess WinSCP has a built-in capability to handle this.
Python version used 3.5.
Step 1:
with open(myNewFile.txt,'w') as fileToUpload:
fileToUpload.write('MyOwnTxt'+'\n')
Step 2:
COMP = remoteServerHost
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(COMP, username=user, password=password, allow_agent = False)
src = myNewFile.txt
dst = "/remotePath/myNewFile.txt"
ftp = ssh.open_sftp()
ftp.put(src , dst)
ftp.close()
ssh.close()
I am little surprised because no one has specified this problem in SO or any other forum. So it makes me feel is there something wrong on my Windows machine :(