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.setDoOutpu t(true);
java.net.Protoc olException: cannot write to a URLConnection if doOutput=false - call setDoOutput(tru e)
at sun.net.www.pro tocol.http.Http URLConnection.g etOutputStream( HttpURLConnecti on.java:817)
at sun.net.www.pro tocol.ftp.FtpUR LConnection.get OutputStream(Ft pURLConnection. java:464)
at roelftp.FTP.mai n(FTP.java:30)
import java.io.Buffere dInputStream;
import java.io.Buffere dOutputStream;
import java.io.File;
import java.io.FileInp utStream;
import java.io.IOExcep tion;
import java.net.Malfor medURLException ;
import java.net.URL;
import java.net.URLCon nection;
public class FTP{
public static void main (String args[]){
System.getPrope rties().put("ft pProxySet","tru e");
System.getPrope rties().put("ft pProxyHost","ft pproxy.xxx.xx") ;
System.getPrope rties().put("ft pProxyPort","21 ");
File source = new File("c:\\debug log.log");
BufferedInputSt ream bis = null;
BufferedOutputS tream bos = null;
try {
URL url = new URL("ftp://user:pwd@users. telenet.be;type =i");
URLConnection urlc = url.openConnect ion();
urlc.setDoOutpu t(true);
// urlc.setDoInput ( true );
bos = new BufferedOutputS tream(urlc.getO utputStream());
bis = new BufferedInputSt ream(new FileInputStream (source.getName ()));
int i;
while ((i = bis.read()) != -1) {
bos.write(i);
}
} catch (MalformedURLEx ception e) {
// TODO Auto-generated catch block
e.printStackTra ce();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTra ce();
} 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
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.setDoOutpu t(true);
java.net.Protoc olException: cannot write to a URLConnection if doOutput=false - call setDoOutput(tru e)
at sun.net.www.pro tocol.http.Http URLConnection.g etOutputStream( HttpURLConnecti on.java:817)
at sun.net.www.pro tocol.ftp.FtpUR LConnection.get OutputStream(Ft pURLConnection. java:464)
at roelftp.FTP.mai n(FTP.java:30)
import java.io.Buffere dInputStream;
import java.io.Buffere dOutputStream;
import java.io.File;
import java.io.FileInp utStream;
import java.io.IOExcep tion;
import java.net.Malfor medURLException ;
import java.net.URL;
import java.net.URLCon nection;
public class FTP{
public static void main (String args[]){
System.getPrope rties().put("ft pProxySet","tru e");
System.getPrope rties().put("ft pProxyHost","ft pproxy.xxx.xx") ;
System.getPrope rties().put("ft pProxyPort","21 ");
File source = new File("c:\\debug log.log");
BufferedInputSt ream bis = null;
BufferedOutputS tream bos = null;
try {
URL url = new URL("ftp://user:pwd@users. telenet.be;type =i");
URLConnection urlc = url.openConnect ion();
urlc.setDoOutpu t(true);
// urlc.setDoInput ( true );
bos = new BufferedOutputS tream(urlc.getO utputStream());
bis = new BufferedInputSt ream(new FileInputStream (source.getName ()));
int i;
while ((i = bis.read()) != -1) {
bos.write(i);
}
} catch (MalformedURLEx ception e) {
// TODO Auto-generated catch block
e.printStackTra ce();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTra ce();
} 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