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