Use storeFile and check its return value
Main Topics
Browse All TopicsI am working on creating a program which is meant to run on our HP-UX system. The purpose of having it run on UNIX is to help with automating our process. There is an app that runs on UNIX which generates a file, and I created a program which takes this file, converts to XML, and ftp's it to our Windows FTP Server (where it is picked up by a vendor).
The problem I am running into is that even though my logs show 'file transfer successful', the file is never uploaded to the FTP server. Code below is from a test program I created just to work on the file transfer specifically. I've tried both the storeFile & remoteStore method. When I use storeFile, it actually uploads an empty file named 123.txt. When I use remoteStore nothing happens, but it does claim the file was transferred successfully.
I'm sure it's something simple like a configuration but I've tried several different things so far - setting transfer type to Binary, using FTPClientConfig to specify a UNIX system, etc. - with no luck. Any help is appreciated.
Thanks in advance.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
afibarra, thanks for the suggesting, but I have an entire app built already using Commons Net 2.0 - would prefer not to go back and have to recreate anything.
CEHJ - thanks for the tip. It did help, but the file still will not transfer. I tried throwing exceptions if success was false, but there does not seem to be any exception occuring because when I try to get the exception message it says null.
Of course this program runs fine when I run it from my Windows PC, it's only when run on UNIX do I have the problem. I had our network admin check the firewall since our UNIX system is on a different vlan but he sees no denied traffic, so I'm not quite sure what else it could be.
Thanks.
CHEJ, one more note - I am executing the jar file from my home dir on UNIX which is where 123.txt is (even though I specify the full path in the program), and when I log into the ftp server using my credentials I am in the directory I am trying to upload to - so I'm not sure any changing of directories is necessary. Thanks.
>>I was expecting something more along the lines of a printStackTrace() output.
You can of course call printStackTrace if you want, but in this case, it's quite obvious what the origin is - IF there's a message ;-)
It's failing probably for the reason i gave: you need to CD (unless at least you can write to the 'root' of the server)
CEHJ, my apologies - I didn't think that was the solution since I am specifying the full file path to the file on UNIX, and since when I connect to the FTP server with my credentials I am in the remote directory that I need to be in and that I have full access to. If the problem was a change directory issue I would assume that it would also fail when I attempt to run this from my windows machine (specifying the windows path to the file on my desktop).
I will play with changing the directories though to see if that fixes the issue. Thanks.
Here is the output:
/home/denisem> ls -l /home/denisem/123.txt
-rw-r--r-- 1 denisem tipixgrp 67 Oct 30 13:32 /home/denisem/123.txt
I did some more tests... the problem is specifically only with the sending of a file.
1. Connect to windows ftp server from UNIX and delete remote file - success
2. Connect to windows ftp server and download remote file to UNIX (using FileOutputStream) - 123.txt gets created in /home/denisem, but no data is transfered so file is 0byte
3. Connect to windows ftp server and upload file to remote server - fail
I used the same 123.txt in the same locations for all cases just to rule out the file or paths being the problem. This seems to point either a configuration issue in the ftp program when ftp'ing between unix & windows - or a network issue. I also checked the FTP server logs - nothing looked out of the ordinary except this line:
[2] Fri 30Oct09 13:36:11 - (003551) REST 0
[6] Fri 30Oct09 13:36:11 - (003551) 350 Restarting at 0. Send STORE or RETRIEVE.
Could it be possible that UNIX is not actually sending these commands? But if that were the case I would think it would not work when I manually ftp from UNIX to Windows. This is very strange indeed. Ultimately I can just create the application to run on a client machine and act as an intermediary but it would be ideal to have my app run directly on the UNIX system. Just not sure where to go from here.
Thanks for your help.
> Sorry, it was a sloppy mistake. I was expecting something more along the lines of a printStackTrace() output.
Its not a mistake. You would get that if an exception was thrown, there is no need to specify a message in the exception
and from what you have said you don't need to change directories
suggest you try a different ftp client as afibarra originally suggested.
Also worth testing on a different ftp server
Will save you wasting time changing things that aren't busted.
objects, thanks for your input. There is a firewall - but our network admin confirmed it is not blocking the ftp traffic. I can't seem to win on UNIX - this is actually the third FTP client that I've tried and found that it worked so well when running from my Windows machine so the entire application is already built. We were going to have this app run from the windows machine but after some consideration thought it would benefit us to have it run directly from UNIX... until we ran into this road block. It just doesn't seem to make much sense - but the fact that I can perform the transfer when executing it manually tells me there is something with this FTP API that UNIX doesn't like...
No luck running it as root. Having some difficulties debugging too. Trying to research bugs to see if this is a known issue. There has to be something happening only because it is UNIX since the same exact code works fine when running from my Windows PC. I may have to consider leaving the FTP out of my application entirely and having our UNIX programmer script the file transfer separately. Either that or I have to leave this as is to be run manually on a windows system. Still trying though...
Thanks.
I absolutely DO NOT believe this!!! Resolution = ftp.enterLocalPassiveMode(
I had ftp.enterRemotePassiveMode
While poking around through the known bugs, someone had suggested using enterLocalPassiveMode() to deal with a 'hanging' issue, so I figured why the heck not try it. I cannot believe that it was something so simple! I am so sorry to have wasted anyone's time. At the very least I hope this post helps someone else in the future who runs into the same issue.
Is there any way to assign points without accepting as a solution? CHEJ I would like to award points for all of your help (sorry everyone else, but CHEJ is the only one who didn't suggest I use a different ftp client) - but I don't want to mess up the web sites problem/solution stats.
Thanks again to everyone, and again my apologies.
>suggest you try a different ftp client as afibarra originally suggested.
Sorry, I didn't mean to offend anyone. This was just a test program, but as I responded to afibarra, I have an entire app developed & tested (on Windows) using Commons Net 2.0 and I preferred to get the test working with this client so I wouldn't have to change my entire app. The actual app uses the FTP for many other functions (not simply a single file transfer) so to me it was worth the time trying to get this client to work if I possibly could. I do appreciate everyone's feedback though!
Business Accounts
Answer for Membership
by: afibarraPosted on 2009-10-30 at 08:24:53ID: 25703886
For simple FTP try "edtFTP" free library:
m/products /edtftpj/d ownload.ht ml
http://www.enterprisedt.co
It´s very simple and intuitive to use.
Hope this helps