Send FTP files with phyton

2

I am sending a file via FTP using Phyton.

My code:

#!/usr/bin/python
import ftplib
import os
filename = "MyFile"
ftp = ftplib.FTP("xx.xx.xx.xx")
ftp.login("UID", "PSW")
ftp.cwd("/Unix/Folder/where/I/want/to/put/file")
os.chdir(r"\windows\folder\which\has\file")
myfile = open(filename, 'r')
ftp.storlines('STOR ' + filename, myfile)
myfile.close()

The problem is with the use of ftp.storlines() or ftp.storbinary() . In the case that the file is binary or text type.

How do I determine which command I should use? Can it always be sent as a binary regardless of what it is?

    
asked by pmdelatorre 26.04.2017 в 17:18
source

1 answer

2

In FTP the idea of the transfer in Ascii is to be able to make compatible the line breaks between systems, for example. on Windows: \r\n on Unix \n . This is because in Ascii mode lines are transferred, and the SO that receives them saves them with the corresponding line break. What to choose? and it will depend on what you are looking for, if you want to upload a text file from a Windows to a Unix (or visceversa) and that it can be read correctly, then in a text editor you would use the storlines() mode, if what you are looking for is to transfer any file without any modification of the content storbinary()

    
answered by 26.04.2017 / 17:36
source