FTP upload files Python

后端 未结 4 1855
星月不相逢
星月不相逢 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 21:56

    Combined both suggestions. Final answer being

    #!/usr/bin/python
    import ftplib
    import os
    filename = "MyFile.py"
    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()
    

提交回复
热议问题