CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    May 2012
    Posts
    1

    Xcopy between two servers

    Hi everyone, I am trying to move files from one folder (server 1) to another folder(server 2) through command xcopy . I am using the editor dev c++. My code works fine if i have to move file within single server but gives error " Invalid parameters " if i am trying between servers.

    Here is the code


    int main(int argc, char *argv[]) {
    time_t start, stop;
    clock_t ticks; long count;

    time(&start);

    int i=0;

    while(1)
    {
    time(&stop);
    if(difftime(stop, start)== 60) // moving file after every one min
    {
    //abc is my folder and have to move to test folder of another server
    //have replaced server name wid server 1 and 2

    system("xcopy server1\C:\abc server2\share\C:\test /e/v/s/f/q");
    system("del c:\\abc /s");
    time(&start);
    }
    }
    }

  2. #2
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: Xcopy between two servers

    The first system call needs a few more '\' s.
    You did it right in the second system call.
    Kurt

  3. #3
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Xcopy between two servers

    Are you sure you can copy it from server to server ?

    XCopy info
    Destination : Specifies the destination of the files you want to copy. This parameter can include a drive letter and colon, a directory name, a file name, or a combination of these.
    It doesn't state that you can copy it from server to server. Only from drive to drive.

  4. #4
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: Xcopy between two servers

    Quote Originally Posted by Skizmo View Post
    Are you sure you can copy it from server to server ?
    I think you can but you have to use shares like
    Code:
    system("xcopy \\\\server1\\C$\\abc C:\\test /e/v/s/f/q");
    to copy from server1 to a local directory
    Kurt

  5. #5
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Xcopy between two servers

    Quote Originally Posted by jha.prakash24 View Post
    Hi everyone, I am trying to move files from one folder (server 1) to another folder(server 2) through command xcopy .
    Did you consider using SHFileOperation instead?
    Victor Nijegorodov

  6. #6
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Xcopy between two servers

    I doubt that any console command is capable of handling network paths that aren't mapped to a drive letter.

    I've had some really bad side-effect from trying to run a .bat file when I wasn't on a mapped network path. The shell defaulted to open in the c:\windows, I was running as admin and the bat file contained del /S *.exe. Well you might guess the result...
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  7. #7
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: Xcopy between two servers

    I'm quite shure that i did it in VB script before.
    But I agree that such an experience is a good reason to use SHFileOperation.
    Kurt

  8. #8
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,539

    Re: Xcopy between two servers

    I do use xcopy within a .bat file sucessfully...

    EDIT:
    OR you can do as Igor suggest in the next post...

    BUT

    also agree with VictorN...I find SHFileOperation easier to use within C++ than a "system" call plus you can also get a progress bar for the file operation. Give SHFileOperation a try...if you need help just give a shout for a sample...


    HTH...
    Last edited by Vanaj; May 4th, 2012 at 12:48 AM. Reason: tech...
    Jim
    ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII

    "The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.

    "Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Xcopy between two servers

    Sorry for disappointing you guys...
    Code:
    D:\>xcopy \\SERVER\exchange\Vartanov\*.jpg \\DDBUILDER\e$\1\*
    \\SERVER\exchange\Vartanov\05.12_Вартанов2 001.jpg
    \\SERVER\exchange\Vartanov\05.12_Вартанов1 001.jpg
    2 File(s) copied
    Best regards,
    Igor

  10. #10
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Xcopy between two servers

    When I got my fingers badly burned I was running XP so I guess you run Win7?
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  11. #11
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Xcopy between two servers

    Nope. It's Windows XP SP3, and you take my word I did this even back in Windows NT4 ages.

    The real difference between the cases, mine and yours, is that mine has paths fully specified while yours might rely on current directory. The latter really must be set to some letter drive based path, otherwise it's %WINDIR%\system32 that automatically implied.
    Best regards,
    Igor

  12. #12
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Xcopy between two servers

    There's always something new to learn...
    Thanks!
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  13. #13
    Join Date
    Dec 2012
    Posts
    1

    Re: Xcopy between two servers

    Thanks for the tip! It saved my life

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured