This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes FTP transaction using a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "FTP transaction using a servlet" Watch "FTP transaction using a servlet" New topic

FTP transaction using a servlet

Deepak Bala

Joined: Feb 24, 2006
Posts: 6661

I wrote a program that uploads files to a FTP server and then downloads it if necessary later on. The program is working successfully but there is a problem when i download the file. The file is an excel file and when i try to open it the following message is displayed... "The file cannot be accessed. The file may be read only or the server where this file is located is not responding.

Well i have already downloaded the file so the latter part of that sentence does not bear any relevance. I tried to download the file using cute FTP and the download was successfull but yet again i got the same error. So is this something to do with file permissions ? Do i have to change the permissions for that file in the FTP server and then save it ? What is going wrong here ?

I opened the file in notepad and all the data is still there but it just wont let me open the file. HELP !!!

Update: I tried to upload and download the file using cute FTP and it worked. But if i upload with the program and then download it screws up. I am using the FTPClient class and the storeFile and retrieveFile functions in that class. any ideas ?
[ July 03, 2006: Message edited by: John Meyers ]

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Santhosh Kumar
Ranch Hand

Joined: Nov 07, 2000
Posts: 242
You have not mentioned which OSs you are using. If you are transferring the files between windows and unix like systems, you need to take care to set the mode correctly for binary file (excel file is binary file). By default mode is ascii so you might have to set to binary.

When you use CuteFTP to upload the file, it would upload the excel file in binary mode.

This is the only hint I'm getting eventhough this issue does not strike anything to the error you getting. However you can give this a try.
Deepak Bala

Joined: Feb 24, 2006
Posts: 6661

I tried specifically setting the file type to binary but no luck. Its so wierd ! All the data has been downloaded and i can see whatever words i have saved in the xls when i open it with notepad. But for some reason it just wont open up !!! Any other ideas people ? Keep em coming. Thanks
Deepak Bala

Joined: Feb 24, 2006
Posts: 6661

Hey it worked !!! guess what i did explicitly mention that the file type was supposed to be binary but... err... i umm forgot to recompile the code after that

Damn ! forgot to check the transfer type in the first place.

Thanks Santhosh
I agree. Here's the link:
subject: FTP transaction using a servlet
Similar Threads
FTP Upload
problem retrieving a zip file from FTP server using
server to server transfer
Regarding FTP froma remote server