ChrisAMK
ChrisAMK

Reputation: 33

FTP put working but FTPlib storlines/storbinary Not working on Linux Device

I'm trying to upload a text file from a Linux device to my FTP server. Using the actual FTP program in Linux works fine but I want to be able to upload from a python script so that I can run other functions.

import ftplib
import os

error = False

try:
    ftp = ftplib.FTP('192.168.8.10')
    ftp.login('rig021', 'Ex021')

    file = open('offlineCache.txt', "rb")
    transfer = ftp.storbinary('STOR offlineResults.txt', file)
    file.close()
    ftp.close()

except ftplib.all_errors as e:
    print(e)
    error = True

I am able to log in Successfully, but the code stays still until this comes up in the console of the server "[rig021] Passive data channel timed out."

From reading Online and on other threads, people say it is a firewall issue. I have disabled the firewall but doubt that is the issue for me since I am able to upload files with the actual FTP common on linux.

If anyone has any ideas or is able to point me in the right direction I'd greatly appreciate it. Cheers

Here is the Log of the Python FTP Client:

UN70HS07M01000532 admin@Rig08Ex:/mnt/sdcard$ python ftpClient.py
*cmd* 'USER rig021'
*put* 'USER rig021\r\n'
*get* '331 Username ok, send password.\r\n'
*resp* '331 Username ok, send password.'
*cmd* 'PASS *****'
*put* 'PASS *****\r\n'
*get* '230 Login successful.\r\n'
*resp* '230 Login successful.'
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '200 Type set to: Binary.\r\n'
*resp* '200 Type set to: Binary.'
*cmd* 'PASV'
*put* 'PASV\r\n'
*get* '227 Entering passive mode (192,168,8,10,200,196).\r\n'
*resp* '227 Entering passive mode (192,168,8,10,200,196).'

This is from the standard FTP Client on linux:

Verbose mode on.
ftp> put offlineCache.txt
local: offlineCache.txt remote: offlineCache.txt
200 Active data connection established.
125 Data connection already open. Transfer starting.
226 Transfer complete.
2614136 bytes sent in 0.255 secs (1e+04 Kbytes/sec)


Upvotes: 0

Views: 1033

Answers (1)

ChrisAMK
ChrisAMK

Reputation: 33

I was looking through Martin Prikryl's profile and i found the answer in one of his related threads. If this happens in ftplib, add

ftp.set_pasv(False)

To the Python Client Script

Upvotes: 1

Related Questions