FTP Client Output Response standard - ftp

After successful FTP file transfer, the the response is used to be "226 File send OK", but suddenly, it has changed to be "226 Transfer complete"
I have below questions:
Does FTP response code has any standard?
Can we customize FTP output response for a specific status code?
Find the standard FTP response for file transfer
$ ftp canopus
Connected to canopus.austin.century.com.
220 canopus.austin.century.com FTP server (Version 4.1 Sat Nov 23 12:52:09 CST 1991) ready.
Name (canopus:eric): dee
331 Password required for dee.
Password:
230 User dee logged in.
ftp> pwd
257 "/home/dee" is current directory.
ftp> cd desktop
250 CWD command successful.
ftp> type ascii
200 Type set to A.
ftp> send typescript
200 PORT command successful.
150 Opening data connection for typescript (128.114.4.99,1412).
226 File send OK.
ftp> cdup
250 CWD command successful.
ftp> bye
221 Goodbye.
Note: suddenly the response text 226 File send OK has changed to 226 Transfer complete
Find the details about FTP responses on wikipedia

RFC 959, 4.2. FTP REPLIES:
An FTP reply consists of a three digit number (transmitted as
three alphanumeric characters) followed by some text. The number
is intended for use by automata to determine what state to enter
next; the text is intended for the human user. It is intended
that the three digits contain enough encoded information that the
user-process (the User-PI) will not need to examine the text and
may either discard it or pass it on to the user, as appropriate.
In particular, the text may be server-dependent, so there are
likely to be varying texts for each reply code.

Related

Can't upload file via FTP on Golang

I'm currently using github.com/jlaffaye/ftp on Go to send files.
I'm trying to connect to an FTP and upload a zipped file of about 700MB.
I connect to server properly and change the working dir but when I'm about to call the Stor function, it responds with "connection refused" and drops.
This is the code:
ftpFile="hola.txt"
fileOpen, err := os.Open(ftpFile) // For read access.
if err != nil {
fmt.Println("error "+ftpFile)
panic(err)
} else {
fmt.Println("abierto "+ftpFile)
}
reader:=bufio.NewReader(fileOpen)
err = client.Stor(ftpDir+ftpFile,reader)
if err != nil {
fmt.Println("error en stor "+ftpDir+ftpFile)
panic(err)
} else {
fmt.Println("subiendo "+ftpFile)
}
defer fileOpen.Close()
I'm opening a file with os.Open then read it with bufio.NewReader and pass it to the Stor function but it disconnects. The FTP is good as I was connected to it via FileZilla, the zipfile or txt file (in this code example) are both good and I believe I'm missing the shot when it comes to the bufio.NewReader but I can't find a working example of reading a file and using this goftp library.
Update:
Here's the logfile
220 Microsoft FTP Service
USER *user goes here*
331 Password required
PASS *plain text password goes here*
230 User logged in.
FEAT
211-Extended features supported:
LANG EN*
UTF8
AUTH TLS;TLS-C;SSL;TLS-P;
PBSZ
PROT C;P;
CCC
HOST
SIZE
MDTM
REST STREAM
211 END
TYPE I
200 Type set to I.
OPTS UTF8 ON
200 OPTS UTF8 command successful - UTF8 encoding now ON.
CWD /web-import/pre/
250 CWD command successful.
PWD
257 "/web-import/pre" is current directory.
PASV
227 Entering Passive Mode (x,x,x,x,x,x).
Update: Looks like someone had the same problem some weeks ago: goftp - 229 Entering Extended Passive Mode now I'll be looking for solutions and will post here.
Update: Changed the script to connect to a CentOS server and got the same error. Now that the FTP server is discarded then there are 2 culprits: goftp package and the script itself.
Update: Tried again with a simpler script following example at documentation and failed again at the same spot. Had to report issue on developer's Github https://github.com/jlaffaye/ftp/issues/272
Update: I connected via terminal and opened FTP from command line. I typed "ls" by mistake and got this error
227 Entering Passive Mode (x,x,x,x,x,x).
ftp: connect: Connection refused
Last Update: After coding and debugging in the end it wasn't the goftp package neither the server neither the client. It was my firewall that blocked my ftp from going PASV. I whitelisted the ip and it worked perfectly.

Mainframe pkunzip generates PEX013W Record(s) being truncated to lrecl=

I'm sending binary .gz files from Linux to z/OS via ftps. The file transfers seem to be fine, but when the mainframe folks pkunzip the file, they get a warning:
PEX013W Record(s) being truncated to lrecl= 996. Record# 1 is 1000 bytes.
Currently I’m sending the site commands:
SITE TRAIL
200 SITE command was accepted
SITE CYLINDERS PRIMARY=50 SECONDARY=50
200 SITE command was accepted
SITE RECFM=VB LRECL=1000 BLKSIZE=32000
200 SITE command was accepted
SITE CONDDISP=delete
200 SITE command was accepted
TYPE I
200 Representation type is Image
...
250 Transfer completed successfully.
QUIT
221 Quit command received. Goodbye.
They could read the file after the pkunzip, but having a warning is not a good thing.
Output from pkunzip:
SDSF OUTPUT DISPLAY RMD0063A JOB22093 DSID 103 LINE 25 COLUMNS 02- 81
COMMAND INPUT ===> SCROLL ===> CSR
PCM123I Authorized services are unavailable.
PAM030I INPUT Archive opened: TEST.FTP.SOA5021.GZ
PAM560I ARCHIVE FASTSEEK processing is disabled.
PDA000I DDNAME=SYS00001,DISP_STATUS=MOD,DISP_NORMAL=CATALOG,DISP_ABNORMAL=
PDA000I SPACE_TYPE=TRK,SPACE_TYPE=CYL,SPACE_TYPE=BLK
PDA000I SPACE_PRIMARY=4194304,SPACE_DIRBLKS=5767182,INFO_ALCFMT=00
PDA000I VOLUMES=DPPT71,INFO_CNTL=,INFO_STORCLASS=,INFO_MGMTCLASS=
PDA000I INFO_DATACLASS=,INFO_VSAMRECORG=00,INFO_VSAMKEYOFF=0
PDA000I INFO_COPYDD=,INFO_COPYMDL=,INFO_AVGRECU=00,INFO_DSTYPE=00
PEX013W Record(s) being truncated to lrecl= 996. Record# 1 is 1000 bytes.
PEX002I TEST.FTP.SOA5021
PEX003I Extracted to TEST.FTP.SOA5021I.TXT
PAM140I FILES: EXTRACTED EXCLUDED BYPASSED IN ERROR
PAM140I 1 0 0 0
PMT002I PKUNZIP processing complete. RC=00000004 4(Dec) Start: 12:59:48.86 End
Is there a better set of site commands to transfer a .gz file from Linux to z/OS to avoid this error?
**** Update ****
Using SaggingRufus's answer below, it turns out it doesn't much matter how you send the .gz file, as long as it's binary. His suggestion pointed us to the parameters sent to the pkunzip for the output file, which was VB and was truncating 4 bytes off the record.
Because it is a variable block file, there are 4 bytes allocated to the record attributes. Allocate the file with an LRECL of 1004 and it will be fine.
Rather than generating a .zip file, perhaps generate a .tar.gz file and transfer it to z/OS UNIX? Tar is shipped with z/OS by default, and Rocket Software provides a port of gzip that is optimized for z/OS.

Force lftp to open binary connections?

The problem: I am trying to create a local mirror of a public FTP site. When I use lftp to do the job it creates a mirror without a problem, but when I try to update the mirror a few days later it becomes very slow due to getting stuck on several files.
Running lftp -d I can see that lftp makes several requests to RETR the file, but these requests result in several **** Timeout - reconnecting messages and after about 2-3 minutes I see
<--- 150 Opening BINARY mode data connection for {filename removed}.`
After this last command the file successfully downloads and lftp proceeds further.
From the manual I understand that BINARY is the default mode for lftp, but somehow it doesn't seem to work for the early requests. Can someone suggest how I can force lftp to always open BINARY mode data connection to download all files?
Here's a MWE:
``lftp -d -u anonymous,anonymous -c "open {url}; get {file}"``
And response from lftp -d:
---- Connecting to {url} ({IP}) port 21
<--- 220 (vsFTPd 3.0.3)
---> FEAT
<--- 211-Features:
<--- EPRT
<--- EPSV
<--- MDTM
<--- PASV
<--- REST STREAM
<--- SIZE
<--- TVFS
<--- 211 End
---> USER anonymous
<--- 331 Please specify the password.
---> PASS anonymous
<--- 230 Login successful.
---> TYPE I
<--- 200 Switching to Binary mode.
---> SIZE {file}
<--- 213 3321
---> MDTM {file}
--- 213 20160318190446
---> PASV
<--- 227 Entering Passive Mode ({IP}).
---- Connecting data socket to ({IP}) port 55380
---- Data connection established
---> RETR {file}
**** Timeout - reconnecting
---- Closing data socket
---- Closing control socket
lftp uses binary mode by default for all file transfers and ascii mode for directory listings. So the binary mode should not be a problem here.
Maybe you have a subtle connectivity problem, sometimes setting net:socket-maxseg to a lower value (e.g. 500) helps.
The ftp command for binary mode is bin so use that command before you get the file.
cd /direc/tory; bin; get file.xml
The problem is that I see
---> TYPE I
<--- 200 Switching to Binary mode.
in your output, so you're already in binary mode. I wonder if you have a different problem? I also see that you're using passive mode (PASV), and that's good because passive works around firewalls and NATs [1], so we need another reason why you see those timeouts.
Do you have any other clues, maybe from ping or netstat?

Is an FTP error (503 Bad sequence of commands) the result of a client issue or a server issue

I have an FTP server running on an AWS virtual server. We have about 100 users connecting to it over the course of a day, uploading images and other files. All but one are working perfectly. Files come in, not a problem.
We have 1 single user that causes the following log lines to be generated - the username and IP has been removed intentionally and the "***" has been added to highlight the error line:
> 227 Entering Passive Mode (54,79,122,6,195,96)
> STOR media/UV1358A_3.jpg
> 150 Opening data channel for file upload to server of "/media/UV1358A_3.jpg"
> 226 Successfully transferred "/media/UV1358A_3.jpg"
> PASV
> 227 Entering Passive Mode (54,79,122,6,195,141)
> STOR media/UV1358A_4.jpg
> 150 Opening data channel for file upload to server of "/media/UV1358A_4.jpg"
> PASV
> 227 Entering Passive Mode (54,79,122,6,195,136)
> 226 Successfully transferred ""
> STOR media/UV1358A_5.jpg
***********************************************
> 503 Bad sequence of commands.
***********************************************
> PASV
> 227 Entering Passive Mode (54,79,122,6,195,80)
> PORT 122,99,115,5,212,227
> 200 Port command successful
> PORT 122,99,115,5,226,227
> 200 Port command successful
> PORT 122,99,115,5,130,124
> 200 Port command successful
> STOR media/UV1358A_9.jpg
> 150 Opening data channel for file upload to server of "/media/UV1358A_9.jpg"
> PORT 122,99,115,5,152,62
> 200 Port command successful
> STOR media/UV1358A_10.jpg
> 150 Opening data channel for file upload to server of "/media/UV1358A_10.jpg"
> PORT 122,99,115,5,161,49
> 200 Port command successful
We're using FileZilla Server 0.9.55 on a Windows 2012 box.
My question, as stated in the title is essentially.. Is this our issue on the server end, or is this theirs?
Is this 503 error always caused by the FTP client screwing something up or is there the possibility that the FTP server is interpreting something wrongly?
I'm happy to go back to the customer and say "It is our issue", but I suspect it's not at our end.
Thanks
The client sends the PASV command to initiate another file transfer before waiting for the previous transfer (the STOR command) to be finished (226 response):
The first transfer starts:
> PASV
< 227 Entering Passive Mode (54,79,122,6,195,141)
> STOR media/UV1358A_4.jpg
< 150 Opening data channel for file upload to server of "/media/UV1358A_4.jpg"
The PASV command for another transfer before the first transfer finished:
> PASV
< 227 Entering Passive Mode (54,79,122,6,195,136)
The first transfer finishes only now. The filename in the message is missing, because the FileZilla Server resets a file transfer data (including the file name) upon processing of the out-of-order PASV command (it actually should have better rejected the PASV command already with the 503).
> 226 Successfully transferred ""
A request for the another transfer. It fails because the FileZilla server forgets the out-of-order PASV command upon completion of the first file transfer.
> STOR media/UV1358A_5.jpg
< 503 Bad sequence of commands.

Implementing FTP protocol according to RFC 959

First this isn't an assignment or for employment. I want to be a better/more secure programmer.
I have read RFC 959, I am at a loss as to how you actually use this to make a program that is compliant. Do I just send the commands as strings and make the server interpret them as the command?
For instance if I sent PWD from the client to the server would I just make the server parse this and send back the current dir name?
For instance if I sent PWD from the client to the server would I just make the server parse this and send back the current dir name?
Yes. That's correct.
The FTP protocol is text-based.
An exchange between the client and the server looks literally like this:
Server: 220 ProFTPD 1.3.5rc3 Server (Debian)
Client: USER user
Server: 331 Password required for user
Client: PASS password
Server: 230 User user logged in
Client: SYST
Server: 215 UNIX Type: L8
Client: PWD
Server: 257 "/home/user" is the current directory

Resources