The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-15-2009
gravi2020 gravi2020 is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 3
Question Using SCP command in IBM AIX to download file from remote to local system

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();
}
}
  #2 (permalink)  
Old 01-30-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,884
Try running the same scp on the command line to see if that produces any meaningful error output. Your program above catches the exception and exits; The InitCause() code apparently does nothing useful.
Sponsored Links
Closed Thread

Bookmarks

Tags
awk, awk trim, downloading file, ibm aix, trim, trim awk, unix using java

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0