Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

FTPClient (Apache) authenticates and connects but...  RSS feed

 
Tommy Griffith
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I get "IT IS CONNECTED" on my console. Now the problem...

after confirming that client.IsConnected(), the following three calls all return nothing, do nothing (no error) and the booleans simply return false...



files_array is empty but I see the files in the FTP directory in explorer

============================================



success is always false

=============================================



success2 is always false and the file is never uploaded to the ftp site.



Again, the connection to the ftp site is established in the code with the same credentials I use when I manually access the ftp in explorer. But everything else just equates to nulls and falses (sans errors). Would anybody have an idea what is going on? Is it maybe another read/write security layer for the server the code is running at the FTP site/directory although the code authenticates and connects?

Thank you so much for reading and for your time.
 
Tommy Griffith
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried something else...





and it's still showing a connection and login_state=true. i deliberately entered bogus login credentials to bomb it and it doesn't seem to care.

This is telling me that I or the server where I'm running this code are either blocked outright from the ftp site (but I access it manually in explorer) or somehow I'm not hitting the actual ftp site? But it's the exact url addy I enter into explorer which I use as the client.connect arg.

Any help would be so appreciated. thank you again.


P.S. I accdientally started a new thread with this response. I am trying to get rid of it. I really apologize for that. I'm typing this while coding at the same time.


 
Tommy Griffith
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, a little more info...

my target ftp server is not a dedicated ftp server...there is a sub-directory which is set as the FTP home or whatever...


for example, I enter the ip 111.22.33.44 into IE address bar, I get the server home page (http://111.22.33.44)


so I need to enter ftp://111.22.33.44 in the IE address bar to open the FTP home directory (and get authenticated) on the server...


So, the FTPClient connect code must be hitting the http server...which is why i am getting nulls on ftp specific calls and it doesn't care about ftp authentication. The problem is for FTPClient, I can't enter ftp:// in the connect arg...



It bombs it...

java.net.unknownhostException ftp://111.22.33.44


What is interesting is the exception is not an org.apache.commons thing, it's java.net.

Well, that's what I have so far. i guess I like to think out loud and outline my steps in case somebody comes along later. If anybody has any input, I still would so appreciate it, and thank you to anybody for reading this far.

 
Paul Clapham
Sheriff
Posts: 22195
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After all that it's unclear to me whether you are even trying to connect to an FTP site or not. I would suggest starting small... open a command line and use the "ftp" command to connect to the IP address which you think has a server connected to it.
 
Tim Moores
Saloon Keeper
Posts: 3564
77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the FTPClient connect code must be hitting the http server
I doubt that, since you said that isConnected() returns true - since the FTP client code only understands FTP, it can't be talking to the HTTP server.

client.connect("ftp://111.22.33.44")...

That won't work, as that method takes a hostname as parameter, not an URL.

java.net.unknownhostException ftp://111.22.33.44 What is interesting is the exception is not an org.apache.commons thing, it's java.net.

That's to be expected, as the Apache code relies on the JRE networking code for low-level stuff.

client.changeWorkingDirectory("/sub1")

That assumes that "sub1" is a top-level directory - is it? If it's a subdirectory, leave out the slash.

I agree with Paul that a good first step would be to use a command-line FTP client and make sure it can connect, and subsequently perform the operations you're trying to automate.
 
Tommy Griffith
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much, guys. I used telnet to sorta go down that confirmation path and also found GetReplyStrings() to get a more precise explanation of what is going on with each step....


1. Telnet confirmed port 21, so I added the port...




2. My login username has a literal "\" in it, believe it or not, and the FTP reply indicated name and pass required. Ultimately, I figured out it needs a double backslash to eliminate the "\" wildcard.



3. So, everything is going well now but the apparently final obstacle is weird...

550 C:\to_be_uploaded\blah.odf: The filename, directory name, or volume label syntax is incorrect


I can't figure this out as a File object is created and delete() is called on it, using the same file path string, so I think it's something funky with how FTPClient reads the file path string, maybe a backslash thing again? thank you.










 
Tim Moores
Saloon Keeper
Posts: 3564
77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this is a string literal in Java code, then yes - the backslashes would need to be escaped by another backslash.
 
Tommy Griffith
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just thought of something, haven't tried it yet...



The stream to the local file is already established for the second arg (fis)...so is the first arg (filename) simply the name of the file within the FTP working directory (no directory path).

I am entering the full local filepath (C:\files_to_upload\blah.pdf) for the first arg (filepath). Maybe this needs to be just "blah.pdf"?
 
Tommy Griffith
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks to have been it, the file uploaded. Thank you everybody for reading through this and for your help. I'm going to try some other stuff with it so I might have more questions or thoughts.
 
Paul Clapham
Sheriff
Posts: 22195
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tommy Griffith wrote:I am entering the full local filepath (C:\files_to_upload\blah.pdf) for the first arg (filepath). Maybe this needs to be just "blah.pdf"?


You've probably figured this out already, but... When you connect to the FTP server and sign in, it will set your current directory to something which may depend on your user ID. If you want to transfer a file somewhere else, you have to use the CD command to change your current directory on the server. And if you want to transfer a file from somewhere other than your current directory on the client, you have to use the LCD command to navigate to the directory where the file is. Then you just use the file's name in the PUT command.

You might also have to change the transfer type to ASCII or BINARY to avoid having your file corrupted by the transfer process.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!