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


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Using SCP command in IBM AIX to download file from remote to local system
# 1  
Old 01-15-2009
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  
Old 01-30-2009
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Use screen command in AIX to scp file to other server

Hello, Please assist me in using screen command in AIX to scp file to other server Best regards, Vishal (10 Replies)
Discussion started by: Vishal_dba
10 Replies

2. Shell Programming and Scripting

ssh sending local variable to remote system

I am running a useradd script, which works locally but I want to take some of that local information and send it to a remote system, ssh keys are set up between the two systems. I am attaching the script, look at the section titled "Sending information to FTP2" Removed attachment, added... (0 Replies)
Discussion started by: slufoot80
0 Replies

3. UNIX for Advanced & Expert Users

Curl Command to download remote certificate

Hi, I have Apache running with the certificates installed. I need a "unix curl" command to download and display remote server certificate. Kindly help. Note: Apache has ""SSLVerifyClient require" set in its configuration. (3 Replies)
Discussion started by: mohtashims
3 Replies

4. AIX

AIX 5.2 installation on 'IBM system p5 type 9110-51A'

Hi All, I am new to AIX, not completly though.. I got a task to install AIX 5.2 on 'IBM system p5 type 9110-51A' server. I tried few things, but i am not able to get to the console of this server to proceed with the installation. I have installed AIX 6.1 earlier, but those servers can be plugged... (4 Replies)
Discussion started by: nd007
4 Replies

5. UNIX for Dummies Questions & Answers

Copy a file from a dvd to the local AIX file system

Hi, I am a newbie to AIX, so please bear with me. I have mounted a dvd drive on AIX. I am trying to copy the file that is on the dvd drive on to the local machine. However, I get an error: cp: c1m_0001.gz: A system call received a parameter that is not valid. Can some one point me to the... (1 Reply)
Discussion started by: anurag1510
1 Replies

6. Red Hat

To find the LATEST file from a dir on REMOTE machine and SCP to local machine?

Hi All, URGENT - Please help me form a scipt for this: I need the LATEST file from a dir on REMOTE machine to be SCP'd to a dir on local machine. (and I need to execute this from local server) I know that the below cmd is used to find the LATEST file from a dir. But this command is not... (3 Replies)
Discussion started by: me_ub
3 Replies

7. HP-UX

How to execute a remote file with local command

Hello, I know this is somewhat strange, but please let me know if possible. I want to execute a program file in the remote machine with command on the local machine. Let me make things more clear. Suppose I have a cc on my local system and do not have that on the remote system. I want to use... (2 Replies)
Discussion started by: Veera_Raghav
2 Replies

8. UNIX for Dummies Questions & Answers

Copying files from a remote server to local system with cygwin

Hi. I'm sorry if I get on people's nerves asking this, but I don't really understand how to do this and unfortunately don't have the time to work through it step by step in books, etc. At University, we have a unix server that hosts our files. we each have a login and password to access it. I... (3 Replies)
Discussion started by: patwa
3 Replies

9. UNIX for Dummies Questions & Answers

File System - Remote or Local??

Is there a way to find if the file systems mounted on a AIX/Linux box is local or remote? (1 Reply)
Discussion started by: Un1xNewb1e
1 Replies

10. UNIX for Dummies Questions & Answers

how to mount a file system of a remote machine to local file system

Hi friends, In my case, there are serveral PCs running Linux in a LAN. I would like to to mount the directory /A_river of machine-A to the file system of another machine machine-B so that I can access files in that directory. I do not know how to do this. The situation is complicated by... (2 Replies)
Discussion started by: cy163
2 Replies
Login or Register to Ask a Question