473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

FTP file via proxy

168 100+
Hello,

I try to upload a file via ftp while using a proxy-server.
My code is giving me the following error even when using: urlc.setDoOutput(true);

java.net.ProtocolException: cannot write to a URLConnection if doOutput=false - call setDoOutput(true)
at sun.net.www.protocol.http.HttpURLConnection.getOut putStream(HttpURLConnection.java:817)
at sun.net.www.protocol.ftp.FtpURLConnection.getOutpu tStream(FtpURLConnection.java:464)
at roelftp.FTP.main(FTP.java:30)



import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class FTP{

public static void main (String args[]){

System.getProperties().put("ftpProxySet","true");
System.getProperties().put("ftpProxyHost","ftpprox y.xxx.xx");
System.getProperties().put("ftpProxyPort","21");


File source = new File("c:\\debuglog.log");
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
URL url = new URL("ftp://user:pwd@users.telenet.be;type=i");
URLConnection urlc = url.openConnection();

urlc.setDoOutput(true);
// urlc.setDoInput( true );
bos = new BufferedOutputStream(urlc.getOutputStream());
bis = new BufferedInputStream(new FileInputStream(source.getName()));
int i;
while ((i = bis.read()) != -1) {
bos.write(i);
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException ioe) { /* ignore */
}
}
if (bos != null) {
try {
bos.close();
} catch (IOException ioe) { /* ignore */
}
}
}

}
}



can please someone tell me what i am doing wrong.
Or can someone tell me how to upload to a ftp-loaction using Proxy
Feb 7 '07 #1
0 1682

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: David Swanson | last post by:
I am trying to configure the proxy section of the machine.config to handle BOTH connecting to hosts that are not "live" but rather defined in my winnt/system32/drivers/etc/hosts file. AND to hosts...
0
by: Jörg Braun | last post by:
Hello NG, i have a problem With WebRequest! i want to download a htaccess saved file over a proxyconnetion with authentication. Download a file what is not saved with htaccess is no problem,...
24
by: Joseph Geretz | last post by:
Up to this point, our application has been using Windows File Sharing to transfer files to and from our application document repository. This approach does not lend itself toward a secure...
3
by: kieran | last post by:
Hi, I am trying to download a file from the Internet. The below code works fine with no proxy server but I am behind a proxy server at work and need to figure out how to include it in the code....
2
by: kieran | last post by:
Hi, I am trying to download a file through a proxy which is causing me lots of permission erors. anyway after hacking at any and all code i could get my hands on, i got this far, where the...
3
by: Matt D | last post by:
I've got two web services that use the same data types and that clients will have to consume. I read the msdn article on sharing types...
0
by: noel.phillips | last post by:
Hi, I have a webservice defined in a class library assembly. It works fine, in that I can inherit from it in a web service project to create a working web service. In the same class library...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
12
by: MimiMi | last post by:
Hi y'all! I'm new at perl, and I'm trying to automate a file fetch. I have this url (in this example called 'https://GetMyFile'), which, when I paste it into a browser, gives me the pop-up "File...
2
dmjpro
by: dmjpro | last post by:
Here is my code import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.net.InetAddress; import java.net.InetSocketAddress;...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.