Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!




Share:
Notifications
Clear all

File Copy Over Network


(@tjsah18)
New Member
Joined: 5 months ago
Posts: 2
Topic starter  
I've been trying to make a program that copies files through network.
I don't know why but String source = L"E:\\Outputs\\083\\jpERP.exe";          //==> OK! is working but the other didn't work.
there are no error, not copied. so it's hard to find the problem.
is there any ideas i can solve this problem?
bool __fastcall TdlgMain::ft_Copy_CopyFile(void)
{
   // need username, password ????
   String source = L"\\\\rs-fs1\\jpDataXE\\jpERP.exe";     // ==> No error, Not copied
//   String source = L"E:\\Outputs\\083\\jpERP.exe";          //==> OK!
//   String source = L"Z:\\jpERP.exe";          //==> Not copied !
   String destin = L"C:\\RS Programs\\jpERP.exe";
   int result;


   if(FileExists(source))
   {
       ShowMessage(L"Found: " + source);
       try{
           result = CopyFile(source.w_str(), destin.w_str(), true);
           ShowMessage(GetLastError());
           if(result)
               ShowMessage(L"Success");
           else
               ShowMessage(L"Failed");
       }
       catch(...){
           ShowMessage(L"CopyFile  - error");
       }
   }
   else{
       ShowMessage(L"No file found...");
       return false;
   }


   return true;
}

ReplyQuote
Topic Tags
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 2005
 

Hi Tjsah18,

what language and development environment are you working with? (looks like a C variant, C# maybe??)
I presume you're running something under Windows (drive letters are only used under Windows).

There can be a lot of reasons why this doesn't work.
Does the server need some kind of authentication?
As far as I remember, most do need some sort of authentication - to avoid this, map the network share as a drive (I could be wrong of course).

Note: I've ran into the same issue with different programming languages.

p.s. I created a new sub-forum for questions like yours, so I moved it there since that seemed more appropriate.


ReplyQuote
(@tjsah18)
New Member
Joined: 5 months ago
Posts: 2
Topic starter  

@hans Hello Hans,

Thank you for your replying!

i'm working with

Language : c++

OS : window 10

development environment : Rad studio

we have a network drive and need an authentication.

I'm trying to copy the file from network drives to local drive.

 thank you,

 


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 2005
 

I very much suspect that authorization fails, and that's why I doesn't work.
As I understand, you cannot add username/password in the URI (under Windows), so that won't be a solution either.

I haven't done any C++/C# programming under Windows in the passed years. So I can only ask our friend Google.

I did find this post, maybe it helps.

As I understand this sets your current "user" to the user you need to be able to access the file (credentials not the same as your current user account):

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

WindowsIdentity idnt = new WindowsIdentity(username, password);

WindowsImpersonationContext context = idnt.Impersonate();

File.Copy(@"\\192.100.0.2\temp", @"D:\WorkDir\TempDir\test.txt", true);

context.Undo();

ReplyQuote

Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: