Ruby NET::FTP Not Resolving Correct IP - ruby

I am trying to connect to an FTP server using:
ftp = Net::FTPFXPTLS.new
ftp.passive=true
ftp.debug_mode=true
ftp.connect('200.111.111.11',21)
ftp.login('Username','Pass')
ftp.chdir('inbound')
ftp.putbinaryfile("./#{filename}", "/#{filename}")
ftp.close()
For the purposes of this example 200.111.111.11 is the correct IP and 10.1.1.1 is the fake IP.
When I connect via an FTP client such as Transmit I connect fine and everything works as normal but in the transcript it states:
Cmd: PASV
227: Entering Passive Mode (10,1,1,1,47,79).
Fixing bogus PASV data address from 10.1.1.1:12111 to 200.111.111.11:12111.
Then when it tries to connect via the ruby script:
get: 425 Failed to establish connection.
When it tries to do any action like LIST or STOR because the PASV command always returns 10.1.1.1:12111.
So is there anyway to ensure the PASV command uses 200.111.111.11 and not what is sent back to it?

This seems to be more of an issue with the gem, there is a solution for it but woud take a little while to implement. In order to save time we simply switched the protocol to use SFTP which works flawlessly. (Switched both server and code)

Related

AIX 7.1 anonymous ftp fails

I have a "vsftpd" server running on a RHEL machine which is configured for anonymous communication.
I am trying to connect to it from a AIX 7.1 machine using ftp client.
ftp -snv host 8043
Connected to host
220 secure FTP service
ftp> user anonymous mypass
234 Proceed with negotiation.
TLS Auth Entered.
Certificate:
....
....
TLSv1/SSLv3 ( ECDHE-RSA-AES256-GCM-SHA384 ), 256 bits
331 Please specify the password.
230 Login successful.
200 PBSZ set to 0.
200 PROT now Private.
ftp> passive
Passive mode on.
ftp> cd /incoming
250 Directory successfully changed.
ftp> quote pwd
257 "/incoming"
ftp> ls -r
227 Entering Passive Mode (XXX,XXX,XXX,XX,XXX,XX).
ftp: connect: Connection timed out
ftp>
As seen above, the cd and quote pwd command seems to work fine. But ls -r and mput commands fail with Connection timed out error.
No real helpful messages on the server logs also.
Please help on debugging and identifying the issue.
PS: The lftp clients from RHEL work fine connecting to the server.
FTP needs to open two connections to work properly. One for control and one for data.
Whenever you get "cd works but ls doesn't", the data connection is not getting established.
Troubleshooting tips:
look for any firewalls/NATs along the way
try toggling active/passive mode, this opens the data connection from the other side
look at what is happening using network debugging tools like tcpdump/wireshark

Unable to Retrieve Directory Using ProFTPD(WHM)

Well, after looking for many solutions. I came here now.
I am setting up WHM/cPanel for hosting website. Everything was going smooth but I am stuck on FTP connection (Server sent passive reply with unroutable address. Using server address instead.)
Server Details:
CentOS Linux release 7.2.1511 (Core)
WHM/cPanel Version 11.58.0.13
FTP Server: PureFTPD
Acutal error while connecting
To fix this issue and get FTP working you need to open up more numbered ports so FTP can connect. I assume you are using CSF.
Login to WHM then go to CSF >> Firewall Configuration >>
allow TCP_In 30000:50000 and TCP_Out 30000:50000
Once you made the changes Restart the firewall
Now you need to make changes in FTP config file to use these ports, you will find this file to this location /etc/pure-ftpd.conf
Now you will see a line as follows and you will need to uncomment it
# Port range for passive connections replies. - for firewalling.
PassivePortRange 30000 50000
Restart FTP Service and should work.

FTP upload in passive mode not working, It opens data connection and times out with "Data channel timed out."

220 Microsoft FTP Service
user user
331 Password required for user.
pass pass
230-Directory has 543,777,456,128 bytes of disk space available.
230 User logged in.
pwd
257 "/" is current directory.
cwd aa6
250 cwd command successful.
pwd
257 "/aa6" is current directory.
pasv
227 Entering Passive Mode (*,*,*,*,201,182).
stor sampleprogram
150 Opening ASCII mode data connection.
425 Data channel timed out.
The above is the FTP done using command-line. When I check with FTP client there is a file with 0 size created.
There's a firewall or NAT between the client and the server that prevents a connection to the port 51638 (= 201 * 2^8 + 182).
If you are not able to transfer files to/from the server from anywhere/any other FTP client, the server was most likely not set up correctly. Particularly the Windows server firewall was not configured with a rule for a data port range. Another option is that the server is not aware of its external IP address. That would be the case, if the part you obfuscated (*,*,*,*) is not the same IP address you connected to.
See my article on FTP Connection Modes for explanation of the network issues with FTP data connection.
And particularly see my article on configuring IIS FTP Server for instructions on configuring the firewall and/or the external IP address.

FTP clients Filezilla and Ftpuse work, but Windows Explorer cannot engage PASV mode

I created a custom FTP server using .NET 4.0. I am running both the client and server on the same Windows 7 machine, and my firewall is entirely disabled. I can connect to it using both FileZilla and FtpUse, establish PASV mode, and browse the contents of folders just fine. The problem comes in when attempting to connect via Windows Explorer. I can log in successfully, but when Explorer sends the PASV command (see client/server exchange below) Explorer pops up a message box that says "FTP Folder Error", "An error occurred opening that folder on the FTP Server. Make sure you have permission to access that folder". The details that follow are the last two responses it received from the server. I found this (http://support.microsoft.com/kb/2754804/en-us) update and installed it, but it didn't help. Anyone have any ideas what this could be? I open the TCP listener before returning a response from the PASV command, so I don't think it's a question of timing.
<< 220 ***********.
>> USER Domain\******
<< 331 Password required.
>> PASS *******
<< 230 Domain\****** logged in.
>> opts utf8 on
<< 200 OPTS UTF8 command successful - UTF8 encoding now on.
>> syst
<< 215 Windows_NT.
>> site help
<< 200
<< 200 End of help.
>> PWD
<< 257 "/".
>> TYPE A
<< 200 Type set to A.
>> PASV
<< 227 Entering Passive Mode (10,0,0,4,7,100)
Originally, I thought the problem might be related to
Windows explorer hangs up FTP connection after PASV command
But I tried opening the passive port ahead of time and it didn't help. Instead, the problem is related to the strictness of Windows Explorer. The IP address supplied as part of the 227 response must be identical to the address of the FTP site the client initially connected. In other words, if the client connects using
ftp://localhost
(which resolves to 127.0.0.1), the IP address provided with the PASV response MUST be 127.0.0.1 - otherwise, Windows Explorer will error. This is not to say that the passive port can't be opened with IPAddress.Any - it can:
var listener = new TcpListener(IPAddress.Any, 0)
However, the address returned with the result must still be 127.0.0.1 (using the above as an example). If the client initially connects with the IP of the machine, say 10.x.x.x for example, the IP address returned with the 227 response must also be 10.x.x.x.
FileZilla must somehow be more forgiving.

JMeter (Active?) FTP to VLTrader

Situation:
I'm using JMeter to load test my communications application (Cleo VLTrader). I'm new to JMeter, and have been able to get HTTP communication working, but not FTP. When I attempt to use a JMeter FTP Request sampler, I can see on the server side that the JMeter is issuing a "PASV" command, and failing shortly thereafter due to a "502 PASV command not available" error.
Question:
How do I need to configure my JMeter FTP Request sampler to connect to my FTP server?
1. Sorry for this but just to ensure: have you ensured that FTP connection succeeds manually, i.e. not from FTP Request in jmeter script but via console/telnet connection or any FTP client utility?
2. FTP Passive mode
Possible cause:
Since your FTP Request fails during PASV command execution can suppose that the root cause is that your ftp server doesn't support passive mode while jmeter's FTP Request uses passive mode by default.
To ensure this try to switch into Passive mode after connecting to your ftp from console,
e.g.
telnet your.ftp.server.url 21
USER yourusername
PASS yourpassword
PASV
or
ftp -d your.ftp.server.url
USER yourusername
PASS yourpassword
passive
or using any ftp client utility which have option to select mode (active/passive) for connection.
If the same issue appears during this - well, the problem is that your ftp server doesn't support passive mode which is used by FTP Request.
See e.g. this for explanation of differences in both the modes.
Possible solution:
As per jmeter sources:
ftp.enterLocalPassiveMode();
switch to passive mode is used by default and there is no possibility to set mode externally in FTP Request configuration screen.
But you can implement ftp request yourself, avoiding usage of FTP Request.
You can use FTPClient realization from Apache Commons Net and script ftp connection in BeanShell Sampler.
Very simplified this may look like:
import org.apache.commons.net.ftp.*;
FTPClient client = new FTPClient();
client.setDataTimeout(3600000);
client.connect(ftpHost,ftpPort);
client.login(userName, userName);
client.setFileType(FTPClient.BINARY_FILE_TYPE);
...
// FTPClient uses 'active mode' by default
if (ftp_passive_mode) {
client.enterLocalPassiveMode();
} else {
client.enterLocalActiveMode();
}
...
client.logout();
client.disconnect();
Maybe also I'm wrong and the reason of your issue hides in another place.
Hope this will help you to diagnose and solve your problem.

Resources