ftplib python module for download / upload / delete / rename / listing files over FTP server

Поделиться
HTML-код
  • Опубликовано: 18 сен 2024

Комментарии • 33

  • @juandiegoflorezruiz
    @juandiegoflorezruiz Год назад +2

    Wasting almost half a day trying to access some ftp. u saved my life with the ssl command. Thank u so much!

  • @randor73
    @randor73 2 года назад +4

    Thank you for a great tutorial! You have a knack for explaining things in its simplest terms! Kudos sir!

  • @alexthewebdesigner1856
    @alexthewebdesigner1856 2 года назад +2

    Sir, thank you so much for posting.this vid! I wasted 2 hours trying to get Paramiko and PySFTP to work, with no success.

  • @prabhatgupta9808
    @prabhatgupta9808 Год назад +2

    Hello, Thank you so much for making this wonderful video, this video is exactly what i was looking for.
    just few more doubts i have, i would really appreciate if you could respond.
    1. is there any way we can copy/move files from one dir to another dir on ftp?
    2. can we read the file on ftp before downloading (as per my requirement i need to check if file is relevant before downloading it).
    Thanks in advance, keep up the good work.

    • @learningsoftwareskills
      @learningsoftwareskills  Год назад

      Hi, thanks for your appreciation
      1. You can explore the rename command to move files remotely the FTP server ( docs.python.org/3/library/ftplib.html#ftplib.FTP.rename )
      2. You can read the contents of an FTP file into a variable using retrlines command as shown in the below example ( docs.python.org/3/library/ftplib.html#ftplib.FTP.retrlines )
      lines = []
      filename="abcd.txt"
      ftp.retrlines("RETR " + filename, lines.append)
      Hope this helps, Cheers👍

  • @bawadhut
    @bawadhut 2 года назад +1

    👍🏼

  • @23nassim92
    @23nassim92 2 года назад +1

    thank you ur the best

  • @AndrésEduardoSuárezRojas
    @AndrésEduardoSuárezRojas Год назад +1

    Gracias!!!

  • @arushichoudhary1380
    @arushichoudhary1380 2 года назад +1

    Thank u it was extremely helpful ,can u also provide a solution about how to find the timestamps of the files on ftp server

    • @learningsoftwareskills
      @learningsoftwareskills  2 года назад +1

      Hi, I have found a solution at stackoverflow.com/a/29027386/2746323
      If you want to find the timestamp of a single file, you can use
      ######################### code start
      timestamp = ftp.voidcmd("MDTM /remote/path/file.txt")[4:].strip()
      time = parser.parse(timestamp)
      ######################### code end
      If you want to find the timestamps of all the files in a remote folder, you can use
      ######################### code start
      from ftplib import FTP
      from dateutil import parser
      # ... (connection to FTP)
      files = ftp.mlsd("/remote/path")
      for file in files:
      name = file[0]
      timestamp = file[1]['modify']
      time = parser.parse(timestamp)
      print(name + ' - ' + str(time))
      ######################### code end
      Hope this helps
      Cheers👍

  • @arushichoudhary1380
    @arushichoudhary1380 2 года назад +2

    Thanku so much it helped a lot also can u please tell me if hostname is some IP address instead of localhost so can the code still works because I;m trying and it is showing me some error

    • @learningsoftwareskills
      @learningsoftwareskills  2 года назад +1

      Hi, using a hostname like "15.25.56.76" is valid. Please mention what error you are getting. You can also check if ssl is required. Also check the connectivity with winscp.
      Hope this helps
      Cheers 👍

    • @arushichoudhary1380
      @arushichoudhary1380 2 года назад

      Thank you that was helpful

  • @ieatmagic8053
    @ieatmagic8053 2 года назад +2

    how to overwrite folders in ftp ?

    • @learningsoftwareskills
      @learningsoftwareskills  2 года назад +1

      Hi, if you want to upload the contents of a whole folder, you can iterate through each file of the local folder using a for loop and upload each file using the storbinary function ( 09:38 ). If a file exists, it will be overwritten anyway.
      If you have nested folders, you have to ensure them in the remote location before uploading files in nested folders.
      Unfortunately, You have to implement the above algorithm yourself. If I find any implementation online, I will comment here
      Hope this helps, Cheers👍

  • @pradeepkumar-h9u7r
    @pradeepkumar-h9u7r 4 месяца назад +1

    Hello Sir, how can we copy folders over ftp?

    • @learningsoftwareskills
      @learningsoftwareskills  4 месяца назад

      Hi, you can't directly copy folders to FTP. You can create a folder in the remote server using the ftp.mkd command and then copy all the files one by one.
      Hope this helps, cheers 👍

  • @sn-op8oi
    @sn-op8oi 2 года назад +1

    Hi is there any process to send file from server location A to another server location B

    • @learningsoftwareskills
      @learningsoftwareskills  2 года назад

      Hi, there can be several approaches to solve this problem depending on the security considerations.
      You can host an FTP server at location A and host the files in the FTP folder, and copy that file to location B using a script in server B.
      Hope this helps, Cheers👍

  • @sn-op8oi
    @sn-op8oi 2 года назад +1

    Hi I need to download the names of those files which were uploaded in last 48 hours. How do I extract the time stamp and get those file names?

    • @learningsoftwareskills
      @learningsoftwareskills  2 года назад

      Hi, use can use ftplib MLSD function to get the modified times along with filenames of all files in an FTP directory. Please see the solution in this link stackoverflow.com/a/29027386
      Hope this helps, Cheers 👍

    • @sn-op8oi
      @sn-op8oi 2 года назад +1

      @@learningsoftwareskills mlsd is blocked is there any other way?

    • @learningsoftwareskills
      @learningsoftwareskills  2 года назад

      @@sn-op8oi Hi, then you can use ftp.dir command. The example code is present in the same stackoverflow post at stackoverflow.com/questions/29026709/how-to-get-ftp-files-modify-time-using-python-ftplib/29027386#29027386
      Cheers 👍

  • @jaikumarm6964
    @jaikumarm6964 Год назад +1

    hi iam getting erro:socket.timeout:timeout in ftp

    • @learningsoftwareskills
      @learningsoftwareskills  Год назад

      Hi, this may be due to firewall policy blocking or network issues. Please check the firewall policy
      Hope this helps, Cheers 👍

    • @jaikumarm6964
      @jaikumarm6964 Год назад +1

      Thank you

  • @fadeblox149
    @fadeblox149 Год назад +1

    i awant to upload dir

    • @learningsoftwareskills
      @learningsoftwareskills  Год назад

      Hi, you can use ftp.mkd to create a folder in the FTP server, then upload the files in the created folder.
      Hope this helps, cheers 👍