简体   繁体   中英

How to copy a file from Unix directory to a Windows directory using Perl?

I'm new to Perl and trying to copy a CSV file from UNIX directory to a Windows shared drive, without using FTP.

Below is my code, in which the source is a CSV file in UNIX directory, whilst "C:/New folder" has been created to receive the file. I put the new folder here as a placeholder as I haven't figured out which shared drive should be used.

use File::Copy;

sub TestCopyFile
{
    my $source = "/home/user/somefolder/somefile.csv";
    my $target = "C:/New folder";

    copy($source, $target);
}

So when I tried to run this from PuTTY, I've been told it is successful. However, I couldn't find the file in the target folder.

Is there anything wrong with my code? Any suggestion is appreciated.

Not a question, really. Windows shared drive means SMB . You need to install and mount the shared drive into your local file system tree.

Example: mount.cifs //the-workstation/the-share ~/mnt/the-workstation/the-share -o rw,vers=3.0,sec=ntlmssp,credentials=$HOME/.smbcredentials,cache=strict,uid=1000,forceuid,gid=100,forcegid,addr=172.xxx.xxx.xxx,file_mode=0644,dir_mode=0755,nounix,serverino,rsize=1048576,wsize=1048576,actimeo=1

If that's too difficult to figure out in the beginning, you can browse the network with smb4k . Once you have found the correct share, it will tell you the appropriate command for mounting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM