Not able to download file from remote to local system Using SCP command in IBM AIX

Joined
Jan 15, 2009
Messages
2
Reaction score
0
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 Code snippet follows:

SIZE="2"]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 == null)
throw new IllegalArgumentException("Cannot accept null filename.");

String tmp = remoteFiles.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')
{
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();
}
}[/SIZE]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top