Using the Apache FTPClient, i can usually connect using the following statements:
FTPClient client = new FTPClient();
client.connect("ftp.myhost.com");
client.login("myUsername", "myPassword");
client.changeWorkingDirectory("/fileFeed");
client.setFileType(FTPClient.BINARY_FILE_TYPE);
client.setFileTransferMode(FTPClient.BLOCK_TRANSFER_MODE);
The above works fine but now i am to connect to the FTP site, i have to use a proxy server. The instructions i got is that i should connect to the proxy server and specify the actual ftp server in the username. So to log on i would use the following details to connect:
ftp ftp.myProxyServer.com
username myUsername#ftp.myhost.com
password myPassword
I tried connecting directly using the command prompt and i can connect to the ftp.myProxyServer.com host and it does forward me to the intended ftp site if i specify myUsername#ftp.myhost.com as the host username. The problem is that the above type of connection is not accepted in Java using Apache FTPClient:
FTPClient client = new FTPClient();
client.connect("ftp.myProxyServer.com");
client.login("myUsername#ftp.myhost.com", "myPassword");
client.changeWorkingDirectory("/fileFeed");
client.setFileType(FTPClient.BINARY_FILE_TYPE);
client.setFileTransferMode(FTPClient.BLOCK_TRANSFER_MODE);
Is there anything i am missing or would the above not work? I tried a direct connection and that works fine.
The FTPClient usually is in active ftp mode, and in case your proxy is not able to initiate a tcp connection back to your client computer (for firewall/DMZ reasons) then you have to switch to passive mode:
FTPClient client = new FTPClient();
client.connect("ftp.myProxyServer.com");
client.login("myUsername#ftp.myhost.com", "myPassword");
client.enterLocalPassiveMode(); //switch from active to passive
client.changeWorkingDirectory("/fileFeed");
...
(Furthermore I would like to recommend to always check the return codes of the method calls, but probably they are ommitted for sake of clarity)
Sorry for the late attempt to answer your question...
Related
I need some help with doing netty socket io over https. I have got it to in my local env but not on a server with secure domain. The server starts but client isn't able to connect. Tried by starting the socket server with IP as well as domain name. For the server to start with domain name as hostname value in setHostname method, I added an entry in /etc/hosts file as following
127.0.0.1 localhost example.com
Socket server started by giving example.com as hostname but client isn't able to connect using the same hostname over https as following
var socket = io.connect('https://example.com:10443')
Tried with options - { secure: true, reconnect: true, rejectUnauthorized : false } too but the same issue.
On server side my configuration is as following
Configuration configuration = new Configuration();
configuration.setHostname("example.com");
configuration.setPort(10443);
configuration.setKeyStorePassword("mypassword");
InputStream stream = getClass().getClassLoader().getResourceAsStream("keystore.jks");
configuration.setKeyStore(stream);
The jsk file was created using keytool command for the same domain (example.com)
Is there something more to be done for the port - 10443 to be used by the socket server? Or is there any other configuration to be done?
Got the solution! I had not mentioned that the domain was set up on cloudflare. Here the issue was with the port I used - 10443. It's not supported by cloudflare. Changed it to 8443 and it worked!
For those who come across this, please find here the list of supported ports that Cloudflare work with. May save much of your time unlike me.
Also, please note that I used my public IP as hostname in setHostname() method so that I don't need anything added in my hosts file. Then gave the actual domain name with https on client side to connect to the server. That's it. Thank you all!
Sandeep
I'm stuck in connecting to FTP over TLS/SSL (FTPS) server. I am using SimpleFTP library through am able to connect FTP server without SSL but could not connect FTPS.
It is giving me this error at line 2 (ftp.connect),
SimpleFTP received an unknown response when connecting to the FTP server:
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
and am using below code
SimpleFTP ftp = new SimpleFTP();
// Connect to an FTP server on port 21.
ftp.connect("xxx.xxx.xxx.xxx", 21, "username", "pwd");
//getting error at (ftp.connect) above line
// Set binary mode.
ftp.bin();
// Change to a new working directory on the FTP server.
ftp.cwd("web");
ftp.disconnect();
The SimpleFTP class/library does not support TLS/SSL at all.
Use the FTPSClient class from the Apache Commons Net library instead.
See the official example for the FTPClient class and just substitute the FTPClient with the FTPSClient.
FTPSClient ftpClient = new FTPSClient();
ftpClient.connect(host);
ftpClient.login(user, password);
The FTPSClient class defaults to an explicit TLS/SSL (recommended). In a rare case you need an implicit TLS/SSL, use new FTPSClient(true).
I installed openfire local server on my laptop and using smack library as xmpp client. I followed this and
this.
After running code I dont see any exception and I don't understand if my user is connected to server. Is there any way to check connection .
Code for making connection to server
XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
config.setUsernameAndPassword(loginUser, passwordUser);
config.setServiceName(ConnectXmpp.DOMAIN);
config.setHost(ConnectXmpp.DOMAIN);
config.setPort(5222);
config.setDebuggerEnabled(true);
connection = new XMPPTCPConnection(config.build());
Log.e("connection",""+connection);//this line to check connection
XMPPConnectionListener connectionListener = new XMPPConnectionListener();
connection.addConnectionListener(connectionListener);
I added user at server and using that username for login at app side.
please guide me where i can check incoming messages fromclient to server , im using embedded database.
Check your callback listener; it will return the connection object.
I am trying to use apache commons to send manual FTP commands as I have to send non-standard FTP commands to a specific server (that accepts them)
Before I try to send these non-standard commands I want to get FTP working manually with commons.net.ftp. Unfortunately I seem to be missing something.
This works fine (i.e. it retrieves the list of files)
FTPClient ftp = new FTPClient();
FTPClientConfig config = new FTPClientConfig();
ftp.configure(config);
ftp.connect("ftp.mozilla.org");
ftp.login("anonymous", "");
ftp.enterLocalPassiveMode();
FTPFile[] fileList = ftp.listFiles("/");
This doesn't
FTPClient ftp = new FTPClient();
FTPClientConfig config = new FTPClientConfig();
ftp.configure(config);
ftp.connect("ftp.mozilla.org");
ftp.login("anonymous", "");
ftp.sendCommand("PASV");
ftp.sendCommand("NLST");
I get the appropriate response for ftp.sendCommand("PASV"); but it times out on ftp.sendCommand("NLST"); finally giving me
425 Failed to establish connection.
I have tried to research the topic but most advice on this error is for people setting up servers (and it's usually a firewall problem).
Why does it work when net.ftp does it, but not when I send the commands manually?
Sending the PASV command manually is not enough, the client has to open the data connection to the port specified by the server in response to the PASV command. This is performed by calling the enterLocalPassiveMode() method. Since sending PASV manually doesn't initialize the data connection you get an error shortly after.
See http://slacksite.com/other/ftp.html#passive for more details on the FTP protocol.
I'm using ftp4j for FTP connection through applet to upload file.
From server, I already open FTP site with port 27, targetURL = local IP address is 192.168.x.xxx, and grant access for user name FTPUser, password xxxx.
FTPClient client = new FTPClient();
client.connect(targetURL, port);
client.setType(client.TYPE_BINARY);
client.login(user, password);
fis = new FileInputStream(targetFile);
client.upload(targetFile);
It connects and uploads file successfully through applet, within internal network
However, when I try to test with external network, router is already configured by using NAT to translate the local IP to external IP: 175.136.xxx.xxx with port 47027 (already tested the FTP Connection using command), I got this error message:
user: FTPUser, password: xxxx port 47027
network: Connecting http://175.136.xxx.xxx:47027/ with proxy=DIRECT
network: Connecting http://175.136.xxx.xxx:20459/ with proxy=DIRECT
it.sauronsoftware.ftp4j.FTPException [code=425, message= Can't open data connection.]
at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2658)
at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2539)
at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2410)
As from the error log, it tried to establish the connection through port 47027, then after that change to 20459 (that I do not know where it comes from).
I can see the file is created in the server FTP site, but with 0 byte.
Anyone knows what's wrong with this situation?
Use passive mode instead. Your side might be blocking the port.