Note that there are some explanatory texts on larger screens.

plurals
  1. POJava code for FTP upload doesn't work properly if launched as windows service
    primarykey
    data
    text
    <p>I'm using java code for uploading some files using FTP. When I compile and run the code everything works perfectly, but if I launch it as a windows service using Java Service Launcher, it doesn't connect to the FTP server at all (it just does the rest of the job, that is moving files to archive folder).</p> <p>Btw, is there any better way for testing child process's output, than writing it's output to a file, than parsing the file content? Here's the code:</p> <pre><code>Runtime runtime = Runtime.getRuntime(); String[] cmd = {"c:\\ftp\\putskripta.bat"}; Process p1 = runtime.exec(cmd); p1.waitFor(); File izlaz = new File("C:\\ftp\\izlaz.txt"); int arrlen = 10000; byte[] infile = new byte[arrlen]; FileInputStream fis = new FileInputStream(izlaz); BufferedInputStream bis = new BufferedInputStream(fis); DataInputStream dis = new DataInputStream(bis); int filelength = dis.read(infile); String filestring = new String(infile, 0, 10000); CharSequence[] sekvenca = {"Invalid command", "Not connected"}; if (!filestring.contains(sekvenca[0]) &amp;&amp; !filestring.contains(sekvenca[1])) { File uploads = new File("C:\\ftp\\Uploads"); File[] uploadfiles = uploads.listFiles(); int godina = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR); int mjesec = Calendar.getInstance().get(Calendar.MONTH)+1; int dan = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); for (int i = 0; i &lt; uploadfiles.length; i++) { if (uploadfiles[i].getName().startsWith("ARTST") || uploadfiles[i].getName().startsWith("BESTE") || uploadfiles[i].getName().startsWith("LAGER") || uploadfiles[i].getName().startsWith("AVISE") || uploadfiles[i].getName().startsWith("KUNDE") || uploadfiles[i].getName().startsWith("BORDE") || uploadfiles[i].getName().startsWith("ENTLA")) { File destinacijaFoldera = new File("C:\\ftp\\MovedUploads\\" + godina + "\\" + mjesec + "\\" + dan); File destinacijaFajla = new File("C:\\ftp\\MovedUploads\\" + godina + "\\" + mjesec + "\\" + dan + "\\" + uploadfiles[i].getName()); if (!destinacijaFoldera.isDirectory()) { destinacijaFoldera.mkdirs(); } File temp = new File(destinacijaFoldera, uploadfiles[i].getName() + "_" + String.valueOf(Calendar.getInstance().get(Calendar.HOUR_OF_DAY)) + String.valueOf(Calendar.getInstance().get(Calendar.MINUTE)) + String.valueOf(Calendar.getInstance().get(Calendar.SECOND))); if (!destinacijaFajla.exists()) { uploadfiles[i].renameTo(destinacijaFajla); } else{ uploadfiles[i].renameTo(temp); } uploadfiles[i].renameTo(new File(destinacijaFoldera, uploadfiles[i].getName())); } } } else {izlaz.delete(); throw new Exception("Neuspio pokusaj uploada");} izlaz.delete(); </code></pre> <p>Just in case, here is the code for "putskripta.bat"</p> <pre><code>@echo off cd c:\ftp\Uploads ftp -s:c:\ftp\putkomande.txt -i localhost &gt; c:\ftp\izlaz.txt </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload