CopyFile() copy from network drive to local drive in windows 10 - c++builder

I'm using Rad Studio for running C++ in window 10.
I've been trying to copy a file from network drive to local drive.
When I tried to copy a file from local to local, it worked!
But when I tried to copy a file from server or mapped driver(Z:),
there are no error, not copied.
So it's hard to find the problem.
I guess that most do need some sort of authentication.
but I'm still stuck with it.
Here is my code.
String source = L"\\\\sever1\\Data\\program1.exe"; // Server to Local : result==> Not copied, no error.
// What I tried to test.
// String source = L"E:\\file1\\083\\program1.exe"; //Local to Local : result==> It works!
// String source = L"Z:\\program1.exe"; //mapped driver : result==> Not copied, no error.
String destination = L"C:\\Our Programs\\program1.exe";
result = CopyFile( source.w_str(), destination.w_str(), true);

Related

In MediaToolkit output file not saved in the specified directory path in the asp.net core with docker

When I try to convert video using MediaToolkit in the local system, then it's working fine, but the same project when I run in docker then output file not saved in the given path.
Also, the output file is not saved in the directory so I am getting null metadata.
Here is my code
using (var engine = new Engine())
{
engine.Convert(inputFile, outputFile, conversionOptions);
engine.GetMetadata(outputFile);
engine.Dispose();
}
FileInfo outputFileInfo = new FileInfo(outputFile.Filename);
Error - Could not find file '/app/e77f2017-ef6e-4115-ba00-73a5c09941a9.mp4'
Can anyone please help me with this?
check the current path (you are working relative)
the program might not run from you think and then "app" directory is not found.

a problem when trying to replace parameters in a lua file

I have never previously worked with lua programming but I have to run a package written in lua language. This package is a command line linux interface and I don't have to know lua programming. In this package I only need to replace some addresses in lua files with my own address and dataset or file names to be able to run the program. But I came across a problem in running a lua file. In this file I replaced the following piece of code:
dofile 'Csv.lua'
local proteinFile = Csv(opt.dataset..".node","r")
local proteinString = proteinFile:readall()
ppFeature = {}
pNumber = {}
for i=1, #proteinString do
local fileName = opt.dataset..'/'..proteinString[i][1]
if file_exists( fileName ) then
local proFile = Csv( fileName, 'r', '\t')
local profile = proFile:readall()
with this one:
dofile 'Csv.lua'
local proteinFile = Csv("/storage/users/ssalmanian/DPPI/myTrain.node","r")
local proteinString = proteinFile:readall()
ppFeature = {}
pNumber = {}
for i=1, #proteinString do
local fileName = '/storage/users/ssalmanian/DPPI/myTrain/proteinString[i][1]'
if file_exists( fileName ) then
local proFile = Csv( fileName, 'r', '\t')
local profile = proFile:readall()
and I got error.
Necessary input files before running the command include a file and a folder with names the same as the -dataset:
A)The suffix of the file is ‘.node’ (myTrain.node). This file has one column which contains names of all proteins.
B) Profile folder with the same name as -dataset (myTrain). This folder contains profiles of all proteins.
The name of the profiles inside this folder is the same as the protein names in ‘.node’ file.
I was wondering if someone could let me know what's wrong with it and which piece of code must be replaced with the following:
local fileName = opt.dataset..'/'..proteinString[i][1]
Thanks.
EDIT:
The package is DPPI package and I tried to run creat_crop.lua code to create two files myTrain_profile_crop_512.t7 and myTrain_number_crop_512.t7 using the following command in a CUDA server :
th creat_crop.lua -dataset myTrain
That creat_crop.lua code is dependent in calling Csv.lua code and needs myTrain.node file and myTrain folder. Here I have added my WinSCP page and the error I get .

Using Grails to store image but could not store outside CATALINA_HOME in production

I'm using Grails 2.5.6 to store uploaded images to folder on a server.
The following are my code to store the image
mpr.multiFileMap.file.each{fileData->
CommonsMultipartFile file = fileData
File convFile = new File(file.getOriginalFilename());
file.transferTo(convFile);
/** Processing File **/
File uploadedFile = new File("${directory}${generatedFileName}.${extension}")
convFile.renameTo(uploadedFile)
}
I have no problem running on development (MacOSX High Sierra)
But when i deployed on production (Ubuntu 14.04 server), i could not save the file outside CATALINA_HOME directory.
I have checked the permission and ownership of the destination directory, but still, the directory was created but the file was never stored.
For Example, i've tried to store the file on /home/tomcat/ directory (/home directory was in separate partition with tomcat which stored it /var), the directory was created, but the file was never stored.
When i put the destination directory within CATALINA_HOME folder, everything works fine. But this was not the scenario i want to do.
You say your destination directory is on another partition, so maybe another filesystem is used on this partition.
Or if you look on the javadoc of the renameTo method it is said :
Many aspects of the behavior of this method are inherently
platform-dependent: The rename operation might not be able to move a
file from one filesystem to another, it might not be atomic, and it
might not succeed if a file with the destination abstract pathname
already exists. The return value should always be checked to make
sure that the rename operation was successful.
...
#return true if and only if the renaming succeeded;
false otherwise
Thus I think the renameTo method is not able to move the file, don't know why but you can rewrite your code like this :
mpr.multiFileMap.file.each{fileData->
CommonsMultipartFile file = fileData
File uploadedFile = new File("${directory}${generatedFileName}.${extension}")
// String originalFilename = file.getOriginalFilename()
// you can store originalFilename in database for example
if(!uploadedFile.getParentFile().exists()) {
uploadedFile.getParentFile().mkdirs()
// You can set permissions on the target directory if you desired, using PosixFilePermission
}
file.transferTo(uploadedFile)
}

How to replace the hosts file on C#

I just want to know how can I completely replace the user's hosts file with another one?
Note: I wana give the user just my .exe compiled file(With my own hosts file attached to it) and after running the exe file the user's hosts file should be replaced with my own hosts file I attached to my exe file.
Simple way, you can use IO library.
string path = "system32\\drivers\\etc\\hosts";
string hostfile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), path);
const string checkIP = "127.0.0.1 localhost";
if (!File.ReadAllLines(hostfile).Contains(checkIP))
File.AppendAllLines(hostfile, new string[] {checkIP});
Do not forget, your program must run with administrator privileges, otherwise you will get an UnauthorizedAccessException exception.

Copying file from local to SharePoint server location

Now on my PC I can use explorer to open a location on our SP server (location eg http://sp.myhost.com/site/Documents/). And from there I can copy/paste a file from eg my C:\ drive.
I need to replicate the copy process progmatically. FileCopy() doesn't do it - seems to be the http:// bit that's causing problems!
Does the server allow WebDAV access? If yes, there are WebDAV clients for Delphi available, including Indy 10.
In case if you are not using BLOB storage all SharePoint files are stored in the database as BLOB objects.
When you access your files with explorer you are using windows service which is reading files from SharePoiont and render it to you. This way you can copy and paste as soon as donwload them from an to SharePoint manually.
To be able to do this automatically you should achive this using the next SP API code:
using (SPSite site = new SPSite("http://testsite.dev"))
{
using (SPWeb web = site.OpenWeb())
{
using (FileStream fs = File.OpenRead(#"C:\Debug.txt"))
{
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, (int) fs.Length);
SPList list = web.GetList("Lists/Test AAD");
SPFile f = list.RootFolder.Files.Add("/Shared Documents/"+Path.GetFileName(fs.Name), buffer);
}
}
}
This will add new "Debug.txt" file to the "Shared Documents" library read from the disk C. To do this for each file just loop through each file in the folder. You can open web only once and do the loop each time when you add file...
Hope it helps,
Andrew

Resources