FTP upload files Python

后端 未结 4 1857
星月不相逢
星月不相逢 2021-01-31 21:11

I am trying to upload file from windows server to a unix server (basically trying to do FTP). I have used the code below

#!/usr/bin/python
import ftplib
import          


        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-31 22:09

    If you are trying to store a non-binary file (like a text file) try setting it to read mode instead of write mode.

    ftp.storlines("STOR " + filename, open(filename, 'rb'))
    

    for a binary file (anything that cannot be opened in a text editor) open your file in read-binary mode

    ftp.storbinary("STOR " + filename, open(filename, 'rb'))
    

    also if you plan on using the ftp lib you should probably go through a tutorial, I'd recommend this article from effbot.

提交回复
热议问题