Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6779611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:24:21+00:00 2026-05-26T16:24:21+00:00

I’m using Jsch 0.1.44 to scp a file from one host to another. The

  • 0

I’m using Jsch 0.1.44 to scp a file from one host to another. The relevant code is the following:

public boolean transferFileToHost(File fileToTransfer, String destDirectory, String destFilename) {
    Channel channel = null;
    try {
        String command = "scp -t "+ destDirectory + destFilename;
        channel = session.openChannel("exec");
        ((ChannelExec)channel).setCommand(command);

        OutputStream out = channel.getOutputStream();
        InputStream in = channel.getInputStream();

        if(!connectToChannel(channel, in)) {
            return false; 
        }

        if(!sendScpCommand(fileToTransfer, command, out, in)) {
            return false;
        }

        if(!sendFileContent(out, fileToTransfer, in)) {
            return false;
        }

        return true;
    } catch (IOException e) {
        logger.error("Error while reading file. Error was: ",e);
    } catch (JSchException e) {
        logger.error("Error while sending ssh commands. Error was: ",e);
    } 
    finally {
        if(channel != null) {
            channel.disconnect();
        }
    }

private boolean sendScpCommand(File file, String command, OutputStream out, InputStream in) throws IOException {
    long filesize=file.length();
    command="C0644 "+filesize+" ";
    command+=file;
    command+="\n";

    out.write(command.getBytes());
    out.flush();
    if (checkAck(in) != 0) {
        return false;
    }
    return true;
}

The command in this line

((ChannelExec)channel).setCommand(command);

looks like this: scp -t /tmp/config.xml and the command in this line

out.write(command.getBytes());

looks like this: C0644 5878 /home/myuser/config.xml

The problem is, that I get the following error from scp: scp: error: unexpected filename: /path/to/config.xml

What is the reason for this error? How can I avoid it?

Any help is highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:24:21+00:00Added an answer on May 26, 2026 at 4:24 pm

    I’ve found a solution. It seems that the source filename in the command must not contain any slashes. To solve this problem you simple have to change this line:

    command+=file;
    

    into this:

    command+=file.getName();
    

    Thats it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm making a simple page using Google Maps API 3. My first. One marker
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
i want to parse a xhtml file and display in UITableView. what is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.