![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to execute a remote file with local command | Veera_Raghav | HP-UX | 2 | 01-16-2009 10:42 AM |
| Copying files from a remote server to local system with cygwin | patwa | UNIX for Dummies Questions & Answers | 3 | 06-12-2008 07:49 AM |
| File System - Remote or Local?? | Un1xNewb1e | UNIX for Dummies Questions & Answers | 1 | 04-11-2008 04:23 PM |
| how to mount a file system of a remote machine to local file system | cy163 | UNIX for Dummies Questions & Answers | 2 | 01-31-2008 09:04 AM |
| how to verify that copied data to remote system is identical with local data. | ynilesh | Shell Programming and Scripting | 3 | 01-31-2008 08:55 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Hi,
When i run the code in solaris unix machine, the file from remote server is getting downloaded. but when i use the same code in IBM AIX remote machine, it is not running. It is saying "Erro during scp transfer." Below is the code. Please give some resolution. SCPClient client = new SCPClient(conn); client.get("/home/userid/bin/test.log.gz", "D:\\"); SCPClient source code snippet below: public void get(String remoteFiles[], String localTargetDirectory) throws IOException { Session sess = null; if ((remoteFiles == null) || (localTargetDirectory == null)) throw new IllegalArgumentException("Null argument."); if (remoteFiles.length == 0) return; String cmd = "scp "; for (int i = 0; i < remoteFiles.length; i++) { if (remoteFiles[i] == null) throw new IllegalArgumentException("Cannot accept null filename."); String tmp = remoteFiles[i].trim(); if (tmp.length() == 0) throw new IllegalArgumentException("Cannot accept empty filename."); cmd += (" " + tmp); } try { sess = conn.openSession(); sess.execCommand(cmd); receiveFiles(sess, remoteFiles, localTargetDirectory); } catch (IOException e) { throw (IOException) new IOException("Error during SCP transfer.").initCause(e); } finally { if (sess != null) sess.close(); } } private void receiveFiles(Session sess, String[] files, String target) throws IOException { byte[] buffer = new byte[8192]; OutputStream os = new BufferedOutputStream(sess.getStdin(), 512); InputStream is = new BufferedInputStream(sess.getStdout(), 40000); os.write(0x0); os.flush(); for (int i = 0; i < files.length; i++) { LenNamePair lnp = null; while (true) { int c = is.read(); if (c < 0) throw new IOException("Remote scp terminated unexpectedly."); String line = receiveLine(is); if (c == 'T') { /* Ignore modification times */ continue; } if ((c == 1) || (c == 2)) throw new IOException("Remote SCP error: " + line); if (c == 'C') { lnp = parseCLine(line); break; } throw new IOException("Remote SCP error: " + ((char) c) + line); } os.write(0x0); os.flush(); File f = new File(target + File.separatorChar + lnp.filename); FileOutputStream fop = null; try { fop = new FileOutputStream(f); long remain = lnp.length; while (remain > 0) { int trans; if (remain > buffer.length) trans = buffer.length; else trans = (int) remain; int this_time_received = is.read(buffer, 0, trans); if (this_time_received < 0) { throw new IOException("Remote scp terminated connection unexpectedly"); } fop.write(buffer, 0, this_time_received); remain -= this_time_received; } } finally { if (fop != null) fop.close(); } readResponse(is); os.write(0x0); os.flush(); } } |
![]() |
| Bookmarks |
| Tags |
| awk, awk trim, downloading file, ibm aix, trim, trim awk, unix using java |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|