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!
April 27, 2021 7:02 PM
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";
ShowMessage(L"Found: " + source);
result = CopyFile(source.w_str(), destin.w_str(), true);
ShowMessage(L"CopyFile - error");
ShowMessage(L"No file found...");
April 28, 2021 5:48 AM
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.
April 29, 2021 5:00 PM
@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.
April 30, 2021 5:27 AM
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):
WindowsIdentity idnt = new WindowsIdentity(username, password);
WindowsImpersonationContext context = idnt.Impersonate();
File.Copy(@"\\22.214.171.124\temp", @"D:\WorkDir\TempDir\test.txt", true);